package lyl.jarfile;

import java.io.*;
import java.util.Map;
import java.util.jar.*;

public class JarRead {
	public static void main(String args[]) throws IOException {
		System.out.println(JarRead.class.getClassLoader().getResource("dom4j/dom4j-1.6.1.jar"));
		args = new String[]{"E:/product/cmspro4.2/dist/cmspro-4.2.0.jar","META-INF/MANIFEST.MF"};
		if (args.length != 2) {
			System.out
					.println("Please provide a JAR filename and file to read");
			System.exit(-1);
		}
		JarFile jarFile = new JarFile(args[0]);
		Map map = jarFile.getManifest().getEntries();
		System.out.println("map="+((java.util.jar.Attributes)map.values().iterator().next()).getValue("Built-Time"));
		
		JarEntry entry = jarFile.getJarEntry(args[1]);
		InputStream input = jarFile.getInputStream(entry);
		process(input);
		jarFile.close();

	}

	private static void process(InputStream input) throws IOException {
		InputStreamReader isr = new InputStreamReader(input);
		BufferedReader reader = new BufferedReader(isr);
		String line;
		while ((line = reader.readLine()) != null) {
			System.out.println(line);
		}
		reader.close();
	}
}